package top.dreamcenter.mcp.client.controller;

import io.modelcontextprotocol.client.McpSyncClient;
import io.modelcontextprotocol.spec.McpSchema;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
public class TestController {

    @Autowired
    private List<McpSyncClient> mcpSyncClients;  // For sync client


    /**
     * http://127.0.0.1:8888/getDir
     *
     * @return
     */
    @GetMapping("/getDir")
    public String getDir() {

        System.out.println("Size:\t" + mcpSyncClients.size());
        for (McpSyncClient client : mcpSyncClients) {
            System.out.println(client.getServerInfo());
            System.out.println("mcpSyncClient名称：" + client.getServerInfo().name());
            if ("secure-filesystem-server".equals(client.getServerInfo().name())) {

                McpSchema.CallToolResult result = client.callTool(new McpSchema.CallToolRequest("list_directory", Map.of("path", "D:\\sofeward")));

                System.out.println(result);

                return result.toString();
            }

        }

        return "NULL";
    }

}
